package com.lpc.kotlintest

import org.junit.Test
import java.util.concurrent.locks.Lock

/**
 * 功能:函数和lambda表达式
 *
 * 描述:
 *
 * Created by lipc0113 on 2018/7/17.
 */
class ExampleUnitTest4 {

    @Test
    fun addition_isCorrect() {

        reformat("111", divideByCamelHumps = true)
    }

    @Test
    fun addition_isCorrect2() {

        println(predicate("brillig2"))
    }

    @Test
    fun addition_isCorrect3() {

        println(compare("11", "111"))
    }

    @Test
    fun addition_isCorrect4() {

//        var a : String? = null // 必须是可空类型，不然强校验没有意义
//        val lenC = a!!.length // 这样做就会报错

//        var a: String? = null
//        var b: String? = null
//        a?.equals(b) ?: b === null

        var y: String? = null
        val x: String? = y as? String

    }

    @Test
    fun addition_isCorrect5() {

        fun gggg() = compare("111", "11")
        max({ x, y -> x.length > y.length })
        max2({gggg()})

        fun toBeSynchroized() = lock2()

        val result = lock(::toBeSynchroized)
    }

    fun max2(test: (b: Boolean) -> Boolean): Boolean {

        if(true){

            return test(1==1)
        }else{
            return false
        }
    }

    fun max(test: (a: String, b: String) -> Boolean): Boolean {

        return false
    }

    fun compare(a: String, b: String): Boolean = a.length < b.length

    fun lock2() : String {

        return ""
    }

    fun <T> lock(body: () -> T ) : T {
        try {
            return body()
        }
        finally {

        }
    }

    val predicate: (String) -> Boolean = ::isOdd

    fun isOdd(s: String) = s == "brillig" || s == "slithy" || s == "tove"

    fun reformat(str: String, normalizeCase: Boolean = true, upperCaseFirstLetter: Boolean = true,
                 divideByCamelHumps: Boolean = false,
                 wordSeparator: Char = ' ') {

    }
}